﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;

namespace Com.CMS263.DAO
{
    public class QuestionDAO:BaseService
    {
        public IList<Question> GetListByPage(int page, int pagesize,int state)
        {
            string hql = "from Question where 1=1";
            if (state == 1)
            {
                hql += " and State=1";
            }
            else if (state == -1)
            {
                hql += " and State=0";
            }
            hql += "  order by AddDate desc";
            return FindList<Question>(hql,null,(page-1)*pagesize,pagesize);
        }
        public int GetCount(int state)
        {
            string hql = "select count(*) from Question where 1=1 ";
            if (state == 1)
            {
                hql += " and State=1";
            }
            else if (state == -1)
            {
                hql += " and State=0";
            }
            return Convert.ToInt32(GetValue(hql));
        }

        /// <summary>
        /// 查询全部
        /// </summary>
        /// <returns></returns>
        public IList<Question> FindAll()
        {
            return DBHelper.ExecuteHQL("from Question where state=1 order by AddDate desc").List<Question>();

        }

        /// <summary>
        /// 查询我的提问
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageSize_2"></param>
        /// <param name="state"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public IList<Question> GetListByPage(int pageSize, int pageSize_2, int state, int type)
        {
            string hql = "from Question where 1=1";
            if (state == 1)
            {
                hql += " and State=1";
            }
            else if (state == -1)
            {
                hql += " and State=0";
            }
            if (type > 0)
            {
                hql = "from Question where UserId=" + type +"";
            }
            hql += "  order by AddDate desc";
            return FindList<Question>(hql, null, (pageSize - 1) * pageSize_2, pageSize_2);
        }
        public int GetCount(int state, int type)
        {
            string hql = "select count(*) from Question where 1=1 ";
            if (state == 1)
            {
                hql += " and State=1";
            }
            else if (state == -1)
            {
                hql += " and State=0";
            }
            if (type > 0)
            {
                hql = "select count(*) from Question where UserId=" + type + "";
            }
            return Convert.ToInt32(GetValue(hql));
        }
    }
}
